package exercise21;

public class ModifyGenericStack<E> {
	private int size = 8;
	private int point = 0;
	
	private E[] list = (E[]) new Object[size];
	
	public int getSize(){
		return size;
	}

	public E peek(){
		return list[point];
	}
	
	public void push(E o){
		if (point == size - 1) {
			size *= 2;
			E[] listTemp = (E[]) new Object[size];
			System.arraycopy(list, 0, listTemp, 0, list.length);
			list = listTemp;
		}
		point += 1;
		list[point] = o;
	}
	
	public E pop(){
		if (isEmpty()) {
			throw new RuntimeException("The stack is empty!");
		}
		E o = list[point];
		list[point] = null;
		point -= 1;
		return o;
	}
	
	public boolean isEmpty(){
		return point == -1 ? true: false;
	}
}
